<!doctype html>
<html>

<head>
	<meta charset="UTF-8">
	<title>添加教育</title>
	<meta name="viewport"
		content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
	<link rel="stylesheet" href="https://cdn.bootcss.com/weui/1.1.3/style/weui.min.css">
	<link rel="stylesheet" href="https://cdn.bootcss.com/jquery-weui/1.2.1/css/jquery-weui.min.css">
	<link rel="stylesheet" href="css/mui.min.css" />
	<!-- build:css css/app.css -->
	<link rel="stylesheet" href="css/base.css" />
	<link rel="stylesheet" href="css/common.css" />
	<!-- endbuild -->
	<style>
		.resume-list .wrapper {
			padding-top: 15px;
			padding-bottom: 1px;
		}

		.resume-list:last-child .wrapper {
			border-bottom: none;
		}
	</style>
</head>

<body>
	<header class="mui-bar mui-bar-nav">
		<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
		<h1 class="mui-title">添加教育</h1>
	</header>
	<div class="mui-content">
		<div class="resume-list">
			<div class="wrapper flex-row-center">
				<label><span class="red">*</span>入学时间</label>
				<input id="entry-time" type="text" placeholder="请选择" data-toggle='date' />
				<i class="mui-icon mui-icon-arrowright"></i>
			</div>
		</div>
		<div class="resume-list">
			<div class="wrapper flex-row-center">
				<label><span class="red">*</span>毕业时间</label>
				<input id="overy-time" type="text" placeholder="请选择" data-toggle='date' />
				<i class="mui-icon mui-icon-arrowright"></i>
			</div>
		</div>
		<div class="resume-list">
			<div class="wrapper flex-row-center">
				<label>
					<span class="red">*</span>学校
				</label>
				<input id="school" type="text" placeholder="请填写" />
			</div>
		</div>
		<div class="resume-list">
			<div class="wrapper flex-row-center">
				<label><span class="red">*</span>学历</label>
				<input id="education" type="text" placeholder="请选择" />
				<i class="mui-icon mui-icon-arrowright"></i>
			</div>
		</div>
		<div class="resume-list">
			<div class="wrapper flex-row-center">
				<label><span class="red">*</span>专业</label>
				<input id="major" type="text" placeholder="请填写" />
			</div>
		</div>
		<button id="save" class="button button-blue">保存</button>
	</div>
	<script src="js/mui.min.js"></script>
	<script src="https://cdn.bootcss.com/jquery/1.11.0/jquery.min.js"></script>
	<script src="https://cdn.bootcss.com/jquery-weui/1.2.1/js/jquery-weui.min.js"></script>
	<!-- build:js js/app.js -->
	<script src="js/api.js"></script>
	<script src="js/tools.js"></script>
	<!-- endbuild -->
	<script>
		var data = {
			resumeId: null,
			entranceTime: null,
			graduationTime: null,
			school: '',
			degree: null,
			specialty: ''
		}
		// 入职时间
		$("#entry-time").calendar({
			onChange: function (p, values, displayValues) {
				data.entranceTime = values[0].replace(/\//g, '-')
			}
		});
		// 离职时间
		$("#overy-time").calendar({
			onChange: function (p, values, displayValues) {
				data.graduationTime = values[0].replace(/\//g, '-')
			}
		});
		// 学历
		$('#education').picker({
			title: '学历',
			cols: [
				{
					textAlign: 'center',
					values: config.resume_edu
				}
			],
			onChange: function (e) {
				data.degree = e.cols[0]['activeIndex']
			}
		})
		$('#save').on('tap', throttle(function() {
			data.resumeId = getRid();
			data.school = $('#school').val();
			data.specialty = $('#major').val();
			console.log(data)
			if (data['entranceTime'] == null) {
				mui.toast('请选择入学时间!')
				return false
			}
			if (data['graduationTime'] == null) {
				mui.toast('请选择毕业时间!')
				return false
			}
			if (data['school'] == '') {
				mui.toast('请填写学校!')
				return false
			}
			if (data['degree'] == null) {
				mui.toast('请选择学历!')
				return false
			}
			if (data['specialty'] == '') {
				mui.toast('请填写专业!')
				return false
			}
			if (!isLogin()) {
				mui.toast('请先登录!');
				return false
			}
			mui.ajax(config.ME_API + 'h5/h5GetResume', {
				data: {
					h5UserId: getUserId()
				},
				dataType: 'json',
				type: 'post',
				timeout: 10000,
				success: function (res) {
					if (res.code == 1) {
						mui.confirm(' 请先创建简历!', '您的简历不完整!', function (res) {
							if (res.index) {
								setTimeout(function () {
									mui.openWindow('my-create-resume.html')
								}, 500)
							}
						})
						return false
					}
					$.ajax({
						url: config.ME_API + 'h5/h5SaveEducation',
						type: 'post',
						data: data,
						success: function (res) {
							if (res.code == 2) {
								mui.toast('添加成功!');
								setTimeout(function () {
									window.history.back()
								}, 1000)
							} else {
								mui.toast(res.msg)
							}
						}
					})
				},
				error: function (xhr, type, errorThrown) {
					mui.toast('请稍后再试!')
				}
			});
		}, 3000))
	</script>
</body>

</html>